﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Enterprise.Management.Gridview
{
    public class GridviewPage
    {
        public List<int> PageSizes { get; set; }
        public int PageSize { get; set; }
        public int TotalCount { get; set; }

        private int pageIndex;
        public int PageIndex
        {
            get { return pageIndex; }
            set
            {
                if (value <= 0) pageIndex = 1;
                else pageIndex = value;
            }
        }
        public int PageTotal
        {
            get
            {
                return Convert.ToInt32(Math.Ceiling((double)TotalCount / PageSize));
            }
        }
        public int StartNum
        {
            get
            {
                int start = Math.Max(0, (PageIndex - 1) * PageSize + 1);
                return Math.Min(start, TotalCount);
            }
        }
        public int EndNum
        {
            get
            {
                return Math.Min(PageIndex * PageSize, TotalCount);
            }
        }

        public GridviewPage()
        {
            PageIndex = 1;
            PageSizes = new List<int>() { 10, 25, 50 };
            PageSize = PageSizes[0];
        }
    }
}